<template>
<div class="profile-page">

    <div class="user-info">
        <div class="container">
            <div class="row">
                <div class="col-xs-12 col-md-10 offset-md-1">
                    <img :src="profile.image" class="user-img" />
                    <h4>{{profile.username}}</h4>
                    <p>{{profile.bio}}</p>
                    <button class="btn btn-sm btn-outline-secondary action-btn">
                        <i class="ion-plus-round"></i>
                        &nbsp;
                        Follow {{profile.username}}
                    </button>
                </div>

            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">

            <div class="col-xs-12 col-md-10 offset-md-1">
                <div class="articles-toggle">
                    <ul class="nav nav-pills outline-active">
                        <li class="nav-item">
                            <a class="nav-link active" href="">My Articles</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="">Favorited Articles</a>
                        </li>
                    </ul>
                </div>

                <div class="article-preview">
                    <div class="article-meta">
                        <a href=""><img :src="profile.image" class="user-img" /></a>
                        <div class="info">
                            <a href="" class="author">{{profile.username}}</a>
                            <span class="date">January 20th</span>
                        </div>
                        <button class="btn btn-outline-primary btn-sm pull-xs-right">
                            <i class="ion-heart"></i> 29
                        </button>
                    </div>
                    <a href="" class="preview-link">
                        <h1>How to build webapps that scale</h1>
                        <p>This is the description for the post.</p>
                        <span>Read more...</span>
                    </a>
                </div>

            </div>

        </div>
    </div>

</div>
</template>

<script>
import { getUsers } from '@/api/profile'
export default {
    name: 'profile',
    // 在匹配组件渲染前会先执行中间件处理
    middleware: 'authenticated',
    async asyncData({ params }){
        const { data } = await getUsers(params.username)
        const { profile } = data
        return {
            profile
        }
    }
}
</script>
